package com.uuj.dome;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName:DruidConfiguration
 * PACKAGE_NAME:com.uuj.dome
 */
@Configuration
public class DruidConfiguration {

    @Bean
    public ServletRegistrationBean statViewServlet() {
        // 创建servlet实体类对象
        ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
        // 设置ip白名单
        bean.addInitParameter("allow", "127.0.0.1");
        // 设置ip黑名单,如果allow和deny共同存在时，deny优先于allow
        bean.addInitParameter("deny", "192.168.0.19");
        // 设置控制台管理用户
        bean.addInitParameter("loginUsername", "druid");
        bean.addInitParameter("loginPassword", "123456");
        // 是否可以重置数据
        bean.addInitParameter("resetEnable", "false");
        return bean;
    }


    @Bean
    public FilterRegistrationBean statFilter() {
        // 创建过滤器实体类对象
        FilterRegistrationBean bean = new FilterRegistrationBean(new WebStatFilter());
        // 设置过滤路径
        bean.addUrlPatterns("/*");
        // 忽略过滤形式
        bean.addInitParameter("exclusions",".js,*.gif,*.png,*.jpg,*.css,*.icon,/druid/*");
        return bean;
    }
}
